/************************************************************************

								Heroes IV
					  Copyright 2001, The 3DO Company

	------------------------------------------------------------------
  						 combat_ai_spell_single_action.cpp

	$Header: $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "combat_ai_spell_single_action.h"

#include <sstream>
#include "battlefield.h"
#include "combat_ai.h"
#include "combat_spell.h"
#include "combat_spell_single_target.h"
#include "debug_message.h"
#include "spell_properties.h"

void t_combat_ai_spell_single_action::weigh_action(t_combat_ai const& ai)
{
	if (has_been_weighed())
		return;

	t_battlefield& battlefield = m_battlefield;
	t_combat_creature* caster = battlefield.get_acting_creature();

	m_single_spell->set_target( m_target );
	m_single_spell->set_caster( caster );

	double weight = m_single_spell->ai_weight( *m_target);

	if (weight <= 0.0)
		m_never_use = true;

	set_weight( weight );
}

void t_combat_ai_spell_single_action::perform_action(void)
{
	t_battlefield &battlefield = m_battlefield;

	m_single_spell->set_target(m_target);

	battlefield.set_spell(m_spell);
	battlefield.begin_spell(m_target);
}
